package offer

import (
	. "GoLeetcode/common"
)

/*
时间复杂度:O(N)
空间复杂度:O(1)
*/

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func removeNthFromEnd(head *ListNode, n int) *ListNode {
	dummy := new(ListNode)
	dummy.Next = head
	p := head
	q := dummy
	for p != nil && n > 0 {
		p = p.Next
		n--
	}
	for p != nil {
		q = q.Next
		p = p.Next
	}
	q.Next = q.Next.Next
	return dummy.Next
}
